<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@page isELIgnored="false" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>客户跟进记录</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link id="bootstrap-style" href="<c:url value="/css/bootstrap.min.css"/>" rel="stylesheet">
	<link href="<c:url value="/css/bootstrap-responsive.min.css"/>" rel="stylesheet">
	<link id="base-style" href="<c:url value="/css/style.css"/>" rel="stylesheet">
	<link id="base-style-responsive" href="<c:url value="/css/style-responsive.css"/>" rel="stylesheet">
	<link href="<c:url value="/css/index.css"/>" rel="stylesheet">
	<link rel="shortcut icon" href="<c:url value="/img/favicon.ico"/>">
	<link href="<c:url value="/css/page.css"/>" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="<c:url value="/css/jquery.datetimepicker.css"/>"/>
	<link href="<c:url value="/css/navuser.css"/>" rel="stylesheet">
	<link href="<c:url value="/css/but.css"/>" rel="stylesheet">
	<script src="<c:url value="/js/jquery-1.9.1.min.js"/>"></script>
	<script src="<c:url value="/js/jquery-migrate-1.0.0.min.js"/>"></script>
	<script type="text/javascript" src="<c:url value="/js/layer/layer.js"/>"></script>
	<script src="<c:url value="/js/laydate/laydate.js"/>"></script>
	<script src="<c:url value="/js/build/jquery.datetimepicker.full.js"/>"></script>
	<script src="<c:url value="/js/orgin.js"/>"></script>
	<script src="<c:url value="/js/filebut.js"/>"></script>
</head>
 <script type="text/javascript">
 
	 $(function(){
		 var custId = $("#custId").val();
		 $.ajax({  
	         url: '<%=basePath%>crm/getLinkmanByCustId?custId='+custId,
	         type: 'GET',  
	         async: false,  
	         cache: false,
	         contentType: false,  
	         processData: false,  
	         dataType: "json",
	         success: function (result) {
	        	//公司信息填充
	        	$("#websiteSpan").html(result.cust.custWebsite);
	        	$("#telSpan").html(result.cust.custTel);
	        	$("#addressSpan").html(result.cust.address);
	        	
	        	var linkmanSelHtm = "";
	        	linkmanSelHtm += "<option mobile='' value=''>未选择</option>";
	        	loadContactByLkmid("",custId);
	        	$.each(result.data,function(index,val){
					//if(index == 0){
					//	$("#lkmId").val(val.id);
					//	$("#mobileSpan").html(val.lkmMobile);
					//	loadContactByLkmid(val.id);
					//}
	        		linkmanSelHtm += "<option mobile='"+val.lkmMobile+"' value='"+val.id+"'>"+val.lkmName+"</option>";
	        	});
	        	$("#linkmanSel").html(linkmanSelHtm);
	         }
	    });
		 $("#linkmanSel").change(function(){
			 $("#lkmId").val($(this).val());
			 var mobile = $("#linkmanSel").find("option:selected").attr("mobile");
			 if(mobile != ""){
				 $("#mobileDiv").show();
				 $("#mobileSpan").html(mobile);
			 }else{
				 $("#mobileDiv").hide();
			 }
			 loadContactByLkmid($(this).val(),custId);
		 });
	 });
	 //根据联系人加载跟进记录
	 function loadContactByLkmid(lkmid,custid){
		 $.ajax({  
		     url: '<%=basePath%>crm/getContactByLkmid?lkmId='+lkmid+'&custId='+custid,
		     type: 'GET',  
		     async: false,  
		     cache: false,
		     contentType: false,  
		     processData: false,  
		     dataType: "json",
		     success: function (result) {
		       	 var contactBdHtm = "";
		       	 $.each(result.list,function(index,val){
		       		contactBdHtm += '<tr class="content-search" style="position: relative;">'
						+'<td colspan="6">';
						if(val.cttPlace != null && val.cttPlace != ""){
							contactBdHtm += '<div style="width: 481px;font-size:16px;height:auto;word-wrap:break-word;text-align: left;"><b style="color: #37c2c2;">地点:'+val.cttPlace+'</b><br>'+val.cttDesc+'</div>';
						}else{
							contactBdHtm += '<div style="width: 481px;font-size:16px;height:auto;word-wrap:break-word;text-align: left;">'+val.cttDesc+'</div>';
						}
						contactBdHtm += '<div style="margin-left: 70px;">'+val.cttDateString+'</div>'
						+'</td>'
						+'</tr>';
		         });
		         $("#contactBd").html(contactBdHtm);
	         }
		});
	 }
    function save(){
    	if($("#cttDesc").val() == null || $("#cttDesc").val() ==''){
    		alert("请填写记录内容");
    		return;
    	}
    	 var formData = new FormData($("#addFollowUp")[0]);
    	 $.ajax({  
	          url: '<%=basePath%>crm/saveContactByLkm',
	          type: 'POST',  
	          data: formData,  
	          dataType:"json",
	          async: false,  
	          cache: false,
	          contentType: false,  
	          processData: false,  
	          success: function (result) {
	                if("addok"==result.msg){
	                	var htmlString = '';
	                	htmlString += '<tr class="content-search" style="position: relative;">'
	                		+'<td colspan="6">';
	                	htmlString += '<div style="width: 481px;font-size:16px;height:auto;word-wrap:break-word;text-align: left;">'+result.cttDesc+'</div>';
	                	htmlString += '<div style="margin-left: 70px;">'+result.cttDateString+'</div>'
	                	+'</td>'
	                	+'</tr>';
	                	$("#cttDesc").val("");
	                    //alert("添加记录成功");
	                    //closebutton();
	                    //location.reload();
	                    $("#contactBd").prepend(htmlString);
	                }else if("addno"==result.msg){
	                    alert("添加记录失败");
	                }else if("custIsBracket"==result.msg){
	                	alert("该客户已封档");
	                }
	          }
     });
    }
     function closebutton() {
 		var index = parent.layer.getFrameIndex(window.name);  
 	 	parent.layer.close(index);  
 	 }
 </script>
<body>
			<div id="content" class="span10" style="width: 100%;background-color:#F9F9F9;">
				<div style="background-color:#FFF;">
				<div style="margin-left:20px;margin-top: 4px;">
					 <center>
						 <span style="font-weight:bold;font-size: 20px;">${custName }&nbsp;&nbsp;<select id="linkmanSel" class="buildselect"></select></span>
					 </center>
				</div>
				<div style="margin-left:20px;margin-top: 28px;">
					 <div id="custWebsiteDiv">
						 <b style="font-size: 12px;">网址&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><span id="websiteSpan" style="font-weight:bold;font-size: 17px;"></span>
					 </div>
					 <div id="custTelDiv">
						 <b style="font-size: 12px;">座机&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><span id="telSpan" style="font-weight:bold;font-size: 17px;"></span>
					 </div>
					 <div id="custAddressDiv">
						 <b style="font-size: 12px;">地址&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><span id="addressSpan" style="font-weight:bold;font-size: 17px;"></span>
					 </div>
					 <div id="mobileDiv" style="display: none;">
						 <b style="font-size: 12px;">联系人手机&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><span id="mobileSpan" style="font-weight:bold;font-size: 17px;"></span>
					 </div>
				</div>
				<div class="row-fluid content-table">
					<table class="table  bootstrap-datatable" style=" border:none; border-spacing:0; border-collapse:collapse;margin:0;padding:0">
					  <thead><tr><td><center><span style="color:#37c2c2">跟进记录</span></center></td></tr></thead>
					  <tbody id="contactBd" style="display:block;height:348px;overflow-y:scroll;">
						
					  </tbody>
				  </table>            
				</div>
				<div style="margin-left:20px;">
					 <div>
						 <form id="addFollowUp">
						 	<input type="hidden" id="custId" name="custId" value="${custId }"/>
						 	<input type="hidden" id="lkmId" name="lkmId" value=""/>
						 	<textarea id="cttDesc" name="cttDesc" rows="5" cols="" style="width: 615px;position: absolute;"></textarea>
						 </form>
					 </div>
					 <div>
						 <button class="but" onclick="save();" style="width: 81px;height: 100px;margin-left: 635px;font-style:oblique;color:white;">跟进</button>
					 </div>
				</div>
			</div>
		</div>
</body>
</html>
